<?php
//+----------------------------------------------------
//| 工具类: 分页处理工具类
//| Author: web_dxj@163.com
//+----------------------------------------------------

namespace Api\Libs;

class PageUtil  {

    public static function getLimit($rows=10) {
        $page = $_REQUEST['page'];
        empty($page) && $page = 1;
        return ($page-1)*$rows.','.$rows;
    }


    public static function getPageHtml($count,$rows=10) {

        $pageNum = floor ($count / $rows);

        $pageNow = $_REQUEST['page'];
        empty($pageNow) && $pageNow = 1;

        if ($pageNow <= 1) $lastUrl = '#';
        else $lastUrl = __ACTION__.'/page/' . ($pageNow - 1);

        if ($pageNow >= $pageNum) $nextUrl = '#';
        else $nextUrl = __ACTION__.'/page/' . ($pageNow + 1);

        $pageHtml = '';
        $pageHtml = $pageHtml . '<li><a href="'.$lastUrl.'">&#8249;</a></li>';
        for ($i=1;$i<=$pageNum;$i++) {
            if ($pageNow == $i)
                $html = '<li><a class="active" href="'. __ACTION__.'/page/'. $i .'">'.$i.'</a></li>';
            else
                $html = '<li><a href="'. __ACTION__.'/page/'. $i .'">'.$i.'</a></li>';

            $pageHtml = $pageHtml . $html;
        }
        $pageHtml = $pageHtml . '<li><a href="'.$nextUrl.'">&#8250;</a></li>';

        return $pageHtml;
    }

}